<template>
  <div class="data-table">
    <el-table 
      :data="data" 
      :loading="loading"
      v-bind="$attrs"
      @selection-change="handleSelectionChange"
    >
      <slot></slot>
    </el-table>
    
    <el-pagination
      v-if="showPagination && pagination"
      class="pagination"
      :current-page="pagination.page"
      :page-size="pagination.size"
      :total="pagination.total"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handlePageChange"
    />
  </div>
</template>

<script setup lang="ts">
interface Pagination {
  page: number
  size: number
  total: number
}

interface Props {
  data: any[]
  loading?: boolean
  showPagination?: boolean
  pagination?: Pagination
}

interface Emits {
  (e: 'page-change', page: number): void
  (e: 'size-change', size: number): void
  (e: 'selection-change', selection: any[]): void
}

withDefaults(defineProps<Props>(), {
  loading: false,
  showPagination: true
})

const emit = defineEmits<Emits>()

const handlePageChange = (page: number) => {
  emit('page-change', page)
}

const handleSizeChange = (size: number) => {
  emit('size-change', size)
}

const handleSelectionChange = (selection: any[]) => {
  emit('selection-change', selection)
}
</script>

<style lang="scss" scoped>
.data-table {
  .pagination {
    margin-top: 20px;
    text-align: right;
  }
}
</style>